Last updated: 2025-10-27

Checks: 5 2

Knit directory: ~/SPP1_mouse_scRNAseq/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20250102) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
/home/hnatri/SPP1_mouse_scRNAseq/ .
/home/hnatri/SPP1_mouse_scRNAseq/code/CART_plot_functions.R code/CART_plot_functions.R
/home/hnatri/SPP1_mouse_scRNAseq/code/colors_themes.R code/colors_themes.R
/home/hnatri/SPP1_mouse_scRNAseq/updated_cluster_markers_top50.tsv updated_cluster_markers_top50.tsv

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 32c5b8d. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .RData
    Ignored:    analysis/figure/

Untracked files:
    Untracked:  .RDataTmp
    Untracked:  Rplots.pdf
    Untracked:  code/scGSVA.R

Unstaged changes:
    Modified:   analysis/update_annotations.Rmd
    Deleted:    code/CellChat.Rout
    Modified:   code/escape_GSEA.R
    Deleted:    code/escape_GSEA.Rout
    Modified:   code/run_rscript.sh

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/update_annotations.Rmd) and HTML (docs/update_annotations.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 32c5b8d heinin 2025-10-26 Updated index and marker expression plots
html 32c5b8d heinin 2025-10-26 Updated index and marker expression plots
Rmd 4fcd1c0 heinin 2025-09-26 Updating annotations after refiltering
html 4fcd1c0 heinin 2025-09-26 Updating annotations after refiltering

Libraries and environment variables

library(workflowr)
library(Seurat)
library(googlesheets4)
library(tidyverse)
library(plyr)
library(ggrepel)
library(patchwork)

setwd("/home/hnatri/SPP1_mouse_scRNAseq/")
set.seed(1234)
options(future.globals.maxSize = 30000 * 1024^2)
reduction <- "integratedSCTumap"

source("/home/hnatri/SPP1_mouse_scRNAseq/code/CART_plot_functions.R")
source("/home/hnatri/SPP1_mouse_scRNAseq/code/colors_themes.R")
source("/home/hnatri/SingleCellBestPractices/scripts/preprocessing_qc_module.R")
source("/home/hnatri/SingleCellBestPractices/scripts/integration_module.R")

# Cluster annotations
gs4_deauth()
cluster_annot  <- gs4_get("https://docs.google.com/spreadsheets/d/127J6C4KF7uBGKUnrPuC1mcsb_wNCN6k1zXKSCbJ6q0M/edit?usp=sharing")
cluster_annot <- read_sheet(cluster_annot, sheet = "Cluster annotation")

Helper functions

recluster_seurat <- function(seurat_object, vars_to_regress){
  
  DefaultAssay(seurat_object) <- "RNA"
  seurat_object <- SCTransform(seurat_object, vars.to.regress = vars_to_regress)
  seurat_object <- RunPCA(seurat_object,
                          reduction.name = "pca",
                          verbose = F)
  pcs <- get_pcs(seurat_object, reduction_name = "pca")
  message(pcs)
  seurat_object <- RunUMAP(seurat_object,
                           reduction = "pca",
                           reduction.name = "umap",
                           dims = 1:min(pcs),
                           return.model = TRUE)
  seurat_object <- FindNeighbors(seurat_object,
                                 reduction = "pca",
                                 dims = 1:min(pcs),
                                 graph.name = c("nn",
                                                "snn"))
  seurat_object <- FindClusters(seurat_object,
                                resolution = c(0.1,0.2,0.3,0.5,0.8,1),
                                graph.name = "snn")
  
  return(seurat_object)
}

Import data

seurat_data <- readRDS("/tgen_labs/banovich/BCTCSF/SPP1_mouse_scRNAseq/scRNAseq_Seurat_dim8_nCount1k_nFeature500_dblrate15_scGSEAmodules.rds")

old_seurat_data <- readRDS("/tgen_labs/banovich/BCTCSF/SPP1_mouse_scRNAseq/scRNAseq_Seurat_dim8_granular_annot.rds")

length(setdiff(colnames(old_seurat_data), colnames(seurat_data)))
length(setdiff(colnames(seurat_data), colnames(old_seurat_data)))
length(intersect(colnames(old_seurat_data), colnames(seurat_data)))

unique(old_seurat_data$DF.class_col)
unique(old_seurat_data$doublet_finder)

seurat_data@meta.data[rownames(seurat_data@meta.data) %in% setdiff(colnames(seurat_data), colnames(old_seurat_data)),]

old_seurat_annot <- old_seurat_data@meta.data[,c("orig.ident", "annot_granular")]
rm(old_seurat_data)
rm(seurat_data)

Reconstructing the UMAP and reclustering

vars_to_regress <- c("G2M.Score",
                     "S.Score",
                     "nCount_RNA",
                     "nFeature_RNA",
                     "percent.mt")

seurat_data <- recluster_seurat(seurat_data, vars_to_regress = vars_to_regress)

#saveRDS(seurat_data, "/tgen_labs/banovich/BCTCSF/SPP1_mouse_scRNAseq/scRNAseq_Seurat_dim8_nCount1k_nFeature500_dblrate15.rds_scGSEAmicroglia_reclustered.rds")

Add old annotations

seurat_data <- readRDS("/tgen_labs/banovich/BCTCSF/SPP1_mouse_scRNAseq/scRNAseq_Seurat_dim8_nCount1k_nFeature500_dblrate15_scGSEAmodules.rds")

seurat_data$annot_granular <- mapvalues(colnames(seurat_data),
                                        from = rownames(old_seurat_annot),
                                        to = old_seurat_annot$annot_granular)

seurat_data$annot_granular <- ifelse(colnames(seurat_data) %in% rownames(old_seurat_annot), seurat_data$annot_granular, NA)

#saveRDS(seurat_data, "/tgen_labs/banovich/BCTCSF/SPP1_mouse_scRNAseq/scRNAseq_Seurat_dim8_nCount1k_nFeature500_dblrate15_scGSEAmodules_reclustered_refAnnot.rds")

Plotting

seurat_data <- readRDS("/tgen_labs/banovich/BCTCSF/SPP1_mouse_scRNAseq/scRNAseq_Seurat_dim8_nCount1k_nFeature500_dblrate15_scGSEAmodules_reclustered_refAnnot.rds")

DimPlot(seurat_data,
        group.by = "snn_res.0.8",
        reduction = "umap",
        label = T) +
  coord_fixed() +
  theme_classic() +
  NoLegend()

Version Author Date
4fcd1c0 heinin 2025-09-26
DimPlot(seurat_data,
        group.by = "annot_granular",
        reduction = "umap",
        label = T) +
  coord_fixed() +
  theme_classic()

Version Author Date
4fcd1c0 heinin 2025-09-26
DimPlot(seurat_data,
        group.by = "predicted.id",
        reduction = "umap",
        label = T) +
  coord_fixed() +
  theme_classic()

Version Author Date
4fcd1c0 heinin 2025-09-26
table(seurat_data$snn_res.0.8, seurat_data$annot_granular)
table(seurat_data$snn_res.0.8, seurat_data$predicted.id)
table(seurat_data$annot_granular, seurat_data$predicted.id)
DimPlot(seurat_data,
        group.by = "Phase",
        reduction = "umap",
        label = T) +
  coord_fixed() +
  theme_classic()

Version Author Date
4fcd1c0 heinin 2025-09-26
# Annotation colors
annots_granular <- sort(unique(seurat_data$annot_granular))
annots_granular_col <- colorRampPalette(brewer.pal(10, "Paired"))(nb.cols <- length(annots_granular))
names(annots_granular_col) <- annots_granular

create_barplot(seurat_data,
               group_var = "snn_res.0.8",
               plot_var = "annot_granular",
               plot_levels = sort(unique(seurat_data$annot_granular)),
               group_levels = sort(unique(seurat_data$snn_res.0.8)),
               plot_colors = annots_granular_col,
               var_names =  c("Frequency", ""),
               legend_title = "")

Version Author Date
4fcd1c0 heinin 2025-09-26
# Cluster colors
snn_res.0.8_clusters <- as.factor(c(0, seq(1:33)))
snn_res.0.8_cluster_col <- colorRampPalette(brewer.pal(10, "Paired"))(nb.cols <- length(snn_res.0.8_clusters))
names(snn_res.0.8_cluster_col) <- levels(snn_res.0.8_clusters)

create_barplot(seurat_data,
               group_var = "annot_granular",
               plot_var = "snn_res.0.8",
               plot_levels = levels(seurat_data$snn_res.0.8),
               group_levels = sort(unique(seurat_data$annot_granular)),
               plot_colors = snn_res.0.8_cluster_col,
               var_names =  c("Frequency", ""),
               legend_title = "")

Version Author Date
4fcd1c0 heinin 2025-09-26
# Reference-based annotation colors
ref_annot_clusters <- sort(unique(seurat_data$predicted.id))
ref_annot_cluster_col <- colorRampPalette(brewer.pal(10, "Paired"))(nb.cols <- length(ref_annot_clusters))
names(ref_annot_cluster_col) <- levels(ref_annot_clusters)

create_barplot(seurat_data,
               group_var = "annot_granular",
               plot_var = "predicted.id",
               plot_levels = levels(seurat_data$predicted.id),
               group_levels = sort(unique(seurat_data$annot_granular)),
               plot_colors = ref_annot_cluster_col,
               var_names =  c("Frequency", ""),
               legend_title = "")

Version Author Date
4fcd1c0 heinin 2025-09-26
create_barplot(seurat_data,
               group_var = "predicted.id",
               plot_var = "annot_granular",
               plot_levels = levels(seurat_data$annot_granular),
               group_levels = sort(unique(seurat_data$predicted.id)),
               plot_colors = annots_granular_col,
               var_names =  c("Frequency", ""),
               legend_title = "")

Version Author Date
4fcd1c0 heinin 2025-09-26
create_barplot(seurat_data,
               group_var = "snn_res.0.8",
               plot_var = "predicted.id",
               plot_levels = levels(seurat_data$predicted.id),
               group_levels = sort(unique(seurat_data$snn_res.0.8)),
               plot_colors = ref_annot_cluster_col,
               var_names =  c("Frequency", ""),
               legend_title = "")

create_barplot(seurat_data,
               group_var = "predicted.id",
               plot_var = "snn_res.0.8",
               plot_levels = levels(seurat_data$snn_res.0.8),
               group_levels = sort(unique(seurat_data$predicted.id)),
               plot_colors = snn_res.0.8_cluster_col,
               var_names =  c("Frequency", ""),
               legend_title = "")

qc_features <- c("nCount_RNA", "nFeature_RNA", "percent.mt")

FeaturePlot(seurat_data,
            #layer = "RNA",
            #slot = "data",
            features = qc_features,
            order = T,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  theme_classic()

Human markers

plot_features <- c("PTMA", "PFN1", "CFL1", "TMSB4X", "TPT1", "TMSB10", "MIF",
                   "PDPN", "NLRP3", "IL1B", "CCL4", "S100A8", "S100A9",
                   "S100A10", "TYROBP", "CD68", "ICAM1", "C1QA", "C1QB", "C1QC",
                   "CD74", "AREG", "CD4", "APOE", "FABP5", "SPP1", "CD274",
                   "CD96", "PTPRC", "CEMIP2", "KLRD1", "CD8A", "NKG7", "IL32",
                   "CD3D", "BTG1", "IFITM2", "ITM2A", "SELL", "GZMB", "CD79A",
                   "ACTA2", "PDGFRB", "COL1A1", "CD163", "MRC1", "ITGAM", "CD14",
                   "CD279", "PDCD1", "TREM2", "TMEM119", "P2RY12", "CX3CR1")

DefaultAssay(seurat_data) <- "RNA_human"
FeaturePlot(seurat_data,
            #assay = "RNA_human",
            slot = "data",
            features = plot_features,
            order = T,
            ncol = 5,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  theme_bw() &
  NoLegend()

Mouse expression modules

FeaturePlot(seurat_data,
            features = c("DAM", "Homeostatic", "MHC_I_machinery", "MHC_II_machinery", "Costimulation_APCB", "Adhesion_immunesynapse"),
            order = T,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  theme_bw() &
  NoLegend()

Expression of each mouse module gene

# Gene sets
gs4_deauth()
genesets  <- gs4_get("https://docs.google.com/spreadsheets/d/127J6C4KF7uBGKUnrPuC1mcsb_wNCN6k1zXKSCbJ6q0M/edit?usp=sharing")
genesets <- read_sheet(genesets, sheet = "Myeloid modules")

DefaultAssay(seurat_data) <- "RNA"
FeaturePlot(seurat_data,
            features = unique(genesets$gene),
            order = T,
            ncol = 5,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  theme_bw() &
  NoLegend()

Top markers for new clusters

markers <- presto::wilcoxauc(seurat_data,
                             group_by = "snn_res.0.8",
                             assay = "data",
                             seurat_assay = "RNA_human")

top_features <- markers %>%  group_by(group) %>% slice_max(order_by = auc, n = 5)

DefaultAssay(seurat_data) <- "RNA_human"
create_dotplot_heatmap(seurat_object = seurat_data,
                       plot_features = unique(top_features$feature),
                       group_var = "snn_res.0.8",
                       group_colors = snn_res.0.8_cluster_col,
                       column_title = "",
                       row_km = 5,
                       col_km = 5,
                       row.order = NULL,
                       col.order = NULL)

output_cluster_markers <- markers %>%
  arrange(dplyr::desc(logFC)) %>%
  group_by(group) %>%
  dplyr::slice(1:50)

#write.table(output_cluster_markers, "/home/hnatri/SPP1_mouse_scRNAseq/updated_cluster_markers_top50.tsv",
#            quote = F, row.names = F, sep = "\t")

Removing problem clusters

Updating annotations

# To build on command line, run Rscript -e "rmarkdown::render('update_annotations.Rmd')"
# Then "mv *.html /home/hnatri/SPP1_mouse_scRNAseq/docs/"

sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats4    grid      stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] mclust_6.0.0                scCustomize_1.1.1          
 [3] glmGamPoi_1.14.3            DoubletFinder_2.0.4        
 [5] scater_1.30.1               scuttle_1.12.0             
 [7] SingleCellExperiment_1.24.0 SummarizedExperiment_1.32.0
 [9] Biobase_2.62.0              GenomicRanges_1.54.1       
[11] GenomeInfoDb_1.38.5         IRanges_2.36.0             
[13] S4Vectors_0.40.2            BiocGenerics_0.48.1        
[15] MatrixGenerics_1.14.0       matrixStats_1.0.0          
[17] SoupX_1.6.2                 circlize_0.4.15            
[19] ComplexHeatmap_2.18.0       viridis_0.6.3              
[21] viridisLite_0.4.2           RColorBrewer_1.1-3         
[23] patchwork_1.1.2             ggrepel_0.9.3              
[25] plyr_1.8.8                  lubridate_1.9.2            
[27] forcats_1.0.0               stringr_1.5.0              
[29] dplyr_1.1.2                 purrr_1.0.1                
[31] readr_2.1.4                 tidyr_1.3.0                
[33] tibble_3.2.1                ggplot2_3.4.2              
[35] tidyverse_2.0.0             googlesheets4_1.1.0        
[37] Seurat_5.0.1                SeuratObject_5.0.1         
[39] sp_1.6-1                    workflowr_1.7.1            

loaded via a namespace (and not attached):
  [1] fs_1.6.2                  spatstat.sparse_3.0-1    
  [3] bitops_1.0-7              httr_1.4.6               
  [5] doParallel_1.0.17         tools_4.3.0              
  [7] sctransform_0.4.1         utf8_1.2.3               
  [9] R6_2.5.1                  lazyeval_0.2.2           
 [11] uwot_0.1.14               GetoptLong_1.0.5         
 [13] withr_2.5.0               gridExtra_2.3            
 [15] progressr_0.13.0          cli_3.6.1                
 [17] Cairo_1.6-0               spatstat.explore_3.2-1   
 [19] fastDummies_1.7.3         labeling_0.4.2           
 [21] sass_0.4.6                spatstat.data_3.0-1      
 [23] ggridges_0.5.4            pbapply_1.7-0            
 [25] parallelly_1.36.0         rstudioapi_0.14          
 [27] generics_0.1.3            shape_1.4.6              
 [29] ica_1.0-3                 spatstat.random_3.1-5    
 [31] Matrix_1.6-5              ggbeeswarm_0.7.2         
 [33] fansi_1.0.4               abind_1.4-5              
 [35] lifecycle_1.0.3           whisker_0.4.1            
 [37] yaml_2.3.7                snakecase_0.11.0         
 [39] SparseArray_1.2.3         Rtsne_0.16               
 [41] paletteer_1.5.0           promises_1.2.0.1         
 [43] crayon_1.5.2              miniUI_0.1.1.1           
 [45] lattice_0.21-8            beachmat_2.18.1          
 [47] cowplot_1.1.1             magick_2.7.4             
 [49] pillar_1.9.0              knitr_1.43               
 [51] rjson_0.2.21              future.apply_1.11.0      
 [53] codetools_0.2-19          leiden_0.4.3             
 [55] glue_1.6.2                getPass_0.2-4            
 [57] data.table_1.14.8         vctrs_0.6.2              
 [59] png_0.1-8                 spam_2.9-1               
 [61] cellranger_1.1.0          gtable_0.3.3             
 [63] rematch2_2.1.2            cachem_1.0.8             
 [65] xfun_0.39                 S4Arrays_1.2.0           
 [67] mime_0.12                 survival_3.5-5           
 [69] gargle_1.4.0              iterators_1.0.14         
 [71] ellipsis_0.3.2            fitdistrplus_1.1-11      
 [73] ROCR_1.0-11               nlme_3.1-162             
 [75] RcppAnnoy_0.0.20          rprojroot_2.0.3          
 [77] bslib_0.4.2               irlba_2.3.5.1            
 [79] vipor_0.4.5               KernSmooth_2.23-21       
 [81] colorspace_2.1-0          ggrastr_1.0.2            
 [83] tidyselect_1.2.0          processx_3.8.1           
 [85] compiler_4.3.0            curl_5.0.0               
 [87] git2r_0.32.0              BiocNeighbors_1.20.2     
 [89] DelayedArray_0.28.0       plotly_4.10.2            
 [91] scales_1.2.1              lmtest_0.9-40            
 [93] callr_3.7.3               digest_0.6.31            
 [95] goftest_1.2-3             presto_1.0.0             
 [97] spatstat.utils_3.0-3      rmarkdown_2.22           
 [99] XVector_0.42.0            htmltools_0.5.5          
[101] pkgconfig_2.0.3           sparseMatrixStats_1.14.0 
[103] highr_0.10                fastmap_1.1.1            
[105] rlang_1.1.1               GlobalOptions_0.1.2      
[107] htmlwidgets_1.6.2         shiny_1.7.4              
[109] DelayedMatrixStats_1.24.0 farver_2.1.1             
[111] jquerylib_0.1.4           zoo_1.8-12               
[113] jsonlite_1.8.5            BiocParallel_1.36.0      
[115] BiocSingular_1.18.0       RCurl_1.98-1.12          
[117] magrittr_2.0.3            GenomeInfoDbData_1.2.11  
[119] dotCall64_1.0-2           munsell_0.5.0            
[121] Rcpp_1.0.10               reticulate_1.29          
[123] stringi_1.7.12            zlibbioc_1.48.0          
[125] MASS_7.3-60               parallel_4.3.0           
[127] listenv_0.9.0             deldir_1.0-9             
[129] splines_4.3.0             tensor_1.5               
[131] hms_1.1.3                 ps_1.7.5                 
[133] igraph_1.4.3              spatstat.geom_3.2-1      
[135] RcppHNSW_0.5.0            reshape2_1.4.4           
[137] ScaledMatrix_1.10.0       evaluate_0.21            
[139] ggprism_1.0.4             tzdb_0.4.0               
[141] foreach_1.5.2             httpuv_1.6.11            
[143] RANN_2.6.1                polyclip_1.10-4          
[145] future_1.32.0             clue_0.3-64              
[147] scattermore_1.2           rsvd_1.0.5               
[149] janitor_2.2.0             xtable_1.8-4             
[151] RSpectra_0.16-1           later_1.3.1              
[153] googledrive_2.1.0         beeswarm_0.4.0           
[155] cluster_2.1.4             timechange_0.2.0         
[157] globals_0.16.2